/*
* PollutantController.java
* Created on  202015/6/15 16:34
* 版本       修改时间          作者      修改内容
* V1.0.1    202015/6/15       longshihui    初始版本
*
*/

package com.infitecs.eyas.combustion;


import com.infitecs.eyas.combustion.model.CalculateBurn;
import com.infitecs.eyas.combustion.model.CalculatePollution;
import com.infitecs.eyas.combustion.service.BurnService;
import com.infitecs.eyas.combustion.service.PollutantService;
import com.infitecs.eyas.expression.service.ExpressionService;
import com.infitecs.eyas.power.dao.PowerDao;
import com.infitecs.eyas.power.model.OperateField;
import com.infitecs.eyas.power.model.Power;
import com.infitecs.eyas.session.SessionService;
import com.infitecs.eyas.session.model.Param;
import com.infitecs.eyas.step.service.StepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * 类的描述信息
 *
 * @author longshihui
 * @version 1.0.1
 */
@Controller
@RequestMapping("/combustion/pollutant")
public class PollutantController {
    @Autowired
    private PollutantService pollutantService;

    @Autowired
    private SessionService sessionService;

    @Autowired
    private ExpressionService expressionService;
    @Autowired
    private BurnService burnService;
    @Autowired
    private StepService stepService;
    @Autowired
    private PowerDao powerDao;

    @RequestMapping("")
    public String getPollutantPage(HttpServletRequest request) {
        String cId = (String) request.getSession().getAttribute("caseId");
        if (cId == null) {
            return "combustion/pollutant";
        }
        int caseId = Integer.parseInt(cId);
        int step = stepService.getMzFxStep(caseId);
        //判断当前方案流程到哪里
        if (step < 6 ) {
            request.setAttribute("step", step);
            return "combustion/pollutant";
        }
        step = stepService.geRsStep(caseId);
        if (step < 11) {
            request.setAttribute("step", step);
            return "combustion/pollutant";
        }
        Power powerTitle = powerDao.getCaseById(cId);
        Map<String, Double> dataMap = burnService.getBurnDataByCaseId(caseId);
        request.setAttribute("powerTitle", powerTitle);
        request.setAttribute("dataMap", dataMap);
        request.setAttribute("caseId", caseId);
        request.setAttribute("message", request.getParameter("message"));
        return "combustion/pollutant";
    }

    @RequestMapping(value = "/saveValueOfPollutantEx", method = {RequestMethod.POST})
    @ResponseBody
    public void saveValueOfPollutantEx(CalculatePollution calculatePollution) {
        pollutantService.saveValueOfPollutant(calculatePollution);
    }

    @RequestMapping(value = "/getCalculateInit", method = {RequestMethod.POST})
    @ResponseBody
    public void getCalculateInit() {
        sessionService.putPollutantValue(sessionService.getCaseId());
    }

    @RequestMapping(value = "/getCalculateData", method = {RequestMethod.POST})
    @ResponseBody
    public CalculatePollution getCalculateData() {
        CalculatePollution calculatePollution = new CalculatePollution();
        calculatePollution.setE184(expressionService.calculate(new Param("RE184")));
        calculatePollution.setE185(expressionService.calculate(new Param("RE185")));
        calculatePollution.setE187(expressionService.calculate(new Param("RE187")));
        calculatePollution.setE188(expressionService.calculate(new Param("RE188")));
        calculatePollution.setE189(expressionService.calculate(new Param("RE189")));
        calculatePollution.setE192(expressionService.calculate(new Param("RE192")));
        calculatePollution.setE193(expressionService.calculate(new Param("RE193")));
        expressionService.calculate(new Param("RE199"));
        calculatePollution.setE205(expressionService.calculate(new Param("RE205")));
        calculatePollution.setE206(expressionService.calculate(new Param("RE206")));
        calculatePollution.setE207(expressionService.calculate(new Param("RE207")));
        calculatePollution.setE208(expressionService.calculate(new Param("RE208")));
        calculatePollution.setE210(expressionService.calculate(new Param("RE210")));
        calculatePollution.setE211(expressionService.calculate(new Param("RE211")));
        calculatePollution.setE212(expressionService.calculate(new Param("RE212")));
        calculatePollution.setE216(expressionService.calculate(new Param("RE216")));
        calculatePollution.setE218(expressionService.calculate(new Param("RE218")));
        calculatePollution.setE330(expressionService.calculate(new Param("RE330")));
        pollutantService.saveVo(calculatePollution);
        return calculatePollution;
    }
}
